<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!--导入模态框-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-import-plan">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Excel信息导入</h4>
            </div>
            <div class="modal-body">
                <form id="importForm">
                    <div class="form-group">
                        <label>模版</label>
                        <a class="out" th:href="@{/file/外购件计划模板.xlsx}">点击下载</a>
                    </div>
                    <div class="form-group">
                        <label>选择Excel文件并上传</label>
                        <input id="import-file" class="btn" type="file" name="file">
                        <p class="help-block">请按模板格式进行导入，信息与模板信息对应。</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button id="btn-import" type="button" class="btn btn-success">
                    <span class="Bold">确定</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--上传附件-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-upload">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">上传附件</h4>
            </div>
            <div class="modal-body">
                <form id="uploadForm">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label>选择附件上传</label>
                        <input class="btn" type="file" name="file">
                        <p class="help-block">多个文件请自行打包上传，大小不要超过100M</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:hasPermission="production:list:edit" id="btn-upload" type="button"
                        class="btn btn-success">
                    <span class="Bold">上传</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content">
    <div class="row" style="margin-bottom: 24px">
        <a th:href="@{/production/list}"
           class="btn btn-default pull-right" style="margin-right: 10px">
            <span class="Bold">取消</span>
        </a>
        <a id="btn-save" shiro:hasPermission="production:list:edit" href="javascript:void(0);"
           class="btn btn-success pull-right" style="margin-right: 10px">
            <span class="Bold">确定</span>
        </a>
    </div>
    <div class="row">
        <form id="sheetForm" class="form-horizontal">
            <div class="col-xs-11 col-xs-offset-1">
                <input type="hidden" name="id" th:value="${makeSheet.id}">
                <table class="t1">
                    <thead>
                    <tr>
                        <td colspan="15">
                            <img th:src="@{/img/logo3.jpg}" width="64px" height="40px" style="margin-top: -30px">
                            <div style="display: inline-block;margin-top: 5px;margin-left: 20px">
                                <span style="letter-spacing: 24px;display: block;line-height: 20px">&nbsp;辽宁忠旺机械设备制造有限公司</span>
                                <span style="display: block;font-size: 12px;line-height: 20px">Liaoning Zhongwang Machinery Equipment Manufacturing Co., Ltd</span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="15" style="font-size: 16px;letter-spacing: 4px;">
                            制作件清单变更单
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" style="width: 8%">项目编号</td>
                        <td style="width: 11%;font-size: 14px;">
                            <input id="sheetForm-proCode" type="text" class="form-control" name="proCode"
                                   th:value="${makeSheet.proCode}" readonly>
                        </td>
                        <td style="width: 8%">项目名称</td>
                        <td colspan="4" style="width: 21%">
                            <input id="sheetForm-proName" type="text" class="form-control" name="proName"
                                   th:value="${makeSheet.proName}" readonly>
                        </td>
                        <td style="width: 8%">项目数量</td>
                        <td style="width: 6%">
                            <input id="sheetForm-proNum" type="number" class="form-control" name="proNum"
                                   th:value="${makeSheet.proNum}" readonly>
                        </td>
                        <td style="width: 6%">类型</td>
                        <td style="width: 9%">
                            <input id="sheetForm-malType" type="type" class="form-control" name="special"
                                   th:value="${makeSheet.special}" readonly>
                            <input type="hidden"  name="specialId" th:value="${makeSheet.specialId}">
                        </td>
                        <td style="width: 6%">部分</td>
                        <td style="width: 9%">
                            <input id="sheetForm-part" type="type" class="form-control" name="part"
                                   th:value="${makeSheet.part}" readonly>
                            <input type="hidden"  name="partId" th:value="${makeSheet.partId}">
                        </td>
                    </tr>

                    <tr>
                        <td></td>
                        <td style="width: 4%">序号</td>
                        <td colspan="3">图号</td>
                        <td colspan="3">图名</td>
                        <td style="width: 6%">数量</td>
                        <td colspan="2">制作件类型</td>
                        <td style="width: 6%">操作类型</td>
                        <td colspan="1">备注</td>
                        <td colspan="2">变更原因</td>
                    </tr>
                    </thead>
                    <tbody id="out">
                    <tr th:each="plan : ${MakePlans}" style="height: 40px">
                        <td th:if="${planStat.index == 0}" th:rowspan="${planStat.size}">更改前</td>
                        <td th:text="${planStat.count}"></td>
                        <td colspan="3" th:text="${plan.drawNo}"></td>
                        <td colspan="3" th:text="${plan.drawName}"></td>
                        <td th:text="${plan.drawNum}"></td>
                        <td colspan="2" th:text="${plan.makeType}"></td>
                        <td></td>
                        <td colspan="1" th:text="${plan.remark}"></td>
                        <td colspan="2"></td>
                    </tr>
                    <tr th:each="plan : ${MakePlans}" th:class="${planStat.index == 0 ? 'after-tr' : ''}" style="height: 40px">
                        <td th:if="${planStat.index == 0}" th:rowspan="${planStat.size}">更改后</td>
                        <td th:text="${planStat.count}"></td>
                        <td colspan="3">
                            <input type="hidden" name="planId" th:value="${plan.id}">
                            <input type="text" class="form-control" name="afterDrawNo" th:value="${plan.afterDrawNo}"
                                   autocomplete="off"  th:style="${plan.technologyChange==2?'color: red':''}+';background-color:#ffffff'" readonly>
                        </td>
                        <td colspan="3">
                            <input type="text" class="form-control" name="afterDrawName" th:value="${plan.afterDrawName}"
                                   autocomplete="off" th:style="${plan.technologyChange==2?'color: red':''}+';background-color:#ffffff'" readonly>
                        </td>
                        <td>
                            <input type="number" step="0.1" class="form-control" name="afterDrawNum" th:value="${plan.afterDrawNum}"
                                   autocomplete="off" th:style="${plan.technologyChange==2?'color: red':''}+';background-color:#ffffff'" readonly>
                        </td>
                        <td colspan="2">
                            <input type="text" class="form-control" name="afterMakeType" th:value="${plan.afterMakeType}"
                                   autocomplete="off" th:style="${plan.technologyChange==2?'color: red':''}+';background-color:#ffffff'" readonly>
                        </td>
                        <td>
                            <input type="text"  class="form-control" style="background-color: white"
                                   th:value="${plan.technologyChange==3?'新增': (plan.technologyChange==2?'删除': (plan.technologyChange==1?'修改':''))}"  readonly>
                        </td>
                        <td colspan="1">
                            <input type="text" class="form-control" name="afterRemark" th:value="${plan.afterRemark}"
                                    autocomplete="off" th:style="${plan.technologyChange==2?'color: red':''}+';background-color:#ffffff'" readonly>
                        </td >
                        <td colspan="2">
                            <select class="form-control" name="changeReason" th:style="${plan.technologyChange==2?'color: red':''}">
                                <option value="">请选择</option>
                                <option  th:each="r : ${reasons}" th:value="${r.name}"
                                        th:text="${r.name}" th:selected="${r.name == plan.changeReason}"></option>
                            </select>
                        </td>

                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="col-xs-10 col-xs-offset-1" style="font-size: 14px;line-height: 200%;">
                <div class="col-xs-3" style="padding-left: 0">提报人： [[${session.user.name}]]</div>
                <div class="col-xs-3 bottom form-inline">联系电话：
                    <input class="form-control" style="width:60%;border: none;border-bottom: 1px solid #000;" type="text" name="postTel" th:value="${makeSheet.postTel}">
                </div>
            </div>
        </form>
    </div>
    <!--<div th:include="include :: tip"></div>-->
</section>
<div th:include="include :: footer"></div>
<script th:src="@{/plugin/SheetJs/xlsx.core.min.js}"></script>
<script th:inline="javascript">

    let tempUrl;

    /** 计算表格序号 */
    /*function computerNo() {
        $("table tbody tr").each(function (i, e) {
            $(this).children("td:first").text(i + 1);
        });
    }*/


    $(function () {


        /** 打开上传模态框 */
        $("#sheetForm").on('click', '.out-upload', function () {
            let id = $(this).parents("tr").find("input[name=planId]").val();
            $("#uploadForm").find("input[name=id]").val(id);
            js.modal.open('modal-upload');
        });
        /** 初始化验证 */
        js.validate.init("uploadForm", {
            fields: {
                file: {
                    validators: {
                        notEmpty: {message: '上传文件不能为空'}
                    }
                }
            }
        });
        /** 上传附件 */
        $("#btn-upload").click(function () {
            var $this = $(this);
            $this.attr('disabled', true);
            js.validSubmit({
                formId: "uploadForm",
                url: ctx + "report/list/change/upload",
                data: new FormData($("#uploadForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.alert(result.msg);
                        js.modal.hide("modal-upload");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
            $this.attr('disabled', false);
        });
        /** 重置表单及验证 */
        js.modal.hideEvent("modal-upload", function () {
            js.validate.reset("uploadForm");
            js.reset("uploadForm");
        })

        /** 保存计划单 */
        $("#btn-save").click(function () {
            ;
            $("#specialse").val($("#sheetForm-malType option:selected").text());
            $("#partName").val($("#part option:selected").text());
            let $this = $(this);
            let res = js.vd({
                id: 'sheetForm',
                notEmpty: ['proCode', 'specialId', 'partId', 'afterDrawName', 'afterDrawNo', 'afterDrawNum', 'afterMakeType', 'postTel','changeReason']
            })
            if (!res) {
                return;
            }
            $this.attr('disabled', true);
            js.submit({
                formId: "sheetForm",
                url: ctx + 'production/list/make/change/modifyEdit',
                data: new FormData($("#sheetForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        location.href = ctx + "production/list";
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
            $this.removeAttr('disabled');
        });

    });
</script>
</body>
</html>
